"""
序列扩充
"""

import random
import re
import time
from datetime import timedelta

import faker

_ = timedelta(days=1)
start = 0


def seq():
    global start
    start += 1
    return start


f = faker.Faker("ZH-CN")
RegisteredReplacementKeywords = {
    "姓": f.last_name,
    "名": f.first_name,
    "姓名": f.name,
    "身份证号": f.ssn,
    "地址": f.address,
    "公司": f.company,
    "年龄": lambda: random.randint(1, 100),
    "时间": f.time,
    "日期": f.date,
    "日期时间": f.date_time,
    "工作类型": f.job,
    "性别": lambda: "男" if random.random() > 0.5 else "女",
    "手机号码": f.phone_number,
    "座机号码": f.phone_number,
    "科目": lambda: "",
    "文本": f.text,
    "$i1,100$": lambda: random.randint(1, 100),
    "时间戳": lambda: time.mktime(time.strptime(str(f.date_time() + _), "%Y-%m-%d %H:%M:%S")),
    "序列": lambda: seq()
}

s1 = f.date_time


def get_char(tag):
    return str(RegisteredReplacementKeywords.get(tag[1], lambda: tag[0])())


def gen_data_from_template(template_str: str, repeat_times: int = 1):
    f = open("1.txt", mode="w", encoding="utf8", )
    for _ in range(repeat_times):
        s = re.sub(r'\$(.*?)\$', get_char, template_str)
        print(s, file=f)
    f.close()


if __name__ == '__main__':
    _template_str = '$序列$'

    gen_data_from_template(_template_str, 100)
